//: simplifying:CollectingParameterDemo.java
package simplifying;

import java.util.*;

import junit.framework.*;

class CollectingParameter extends ArrayList {}

class CollectingParameter2 /*extends ArrayList */{
	List<String> list ;
	
	public CollectingParameter2() {
		list = new ArrayList<String>();
	}

	public List<String> getList() {
		return list;
	}
	
	@Override
	public String toString() {
		return list.toString();
	}
}

class Filler {
	public void f(CollectingParameter2 cp) {
		cp.getList().add("accumulating");
	}
	
	public void f(CollectingParameter cp){
		cp.add("accumulating");
	}

	public void g(CollectingParameter cp) {
		cp.add("items");
	}
	
	public void g(CollectingParameter2 cp) {
		cp.getList().add("items");
	}

	public void h(CollectingParameter cp) {
		cp.add("as we go");
	}
	
	public void h(CollectingParameter2 cp) {
		cp.getList().add("as we go");
	}
	
}

public class CollectingParameterDemo extends TestCase {
	public void test() {
		Filler filler = new Filler();
		CollectingParameter2 cp = new CollectingParameter2();
		filler.f(cp);
		filler.g(cp);
		filler.h(cp);
		String result = "" + cp;
		System.out.println(cp);
		assertEquals(result, "[accumulating, items, as we go]");
	}

	public static void main(String[] args) {
		junit.textui.TestRunner.run(CollectingParameterDemo.class);
	}
} // /:~
